package cn.edu.pku.service;

import cn.edu.pku.entity.BookNote;
import cn.edu.pku.entity.BookNoteDetail;
import cn.edu.pku.entity.Borrower;
import cn.edu.pku.mapper.BookNoteMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ming.qin on 2017/4/20.
 */
@Service
public class BookNoteService {

    @Autowired
    BookNoteMapper bookNoteMapper;

    public PageInfo<BookNote> listBookNote(int page, int size,String bookName,String author) {
        PageHelper.startPage(page,size);
        List<BookNote> booknoteList = bookNoteMapper.selectByCondition(bookName,author);
        PageInfo<BookNote> pageInfo = new PageInfo<>(booknoteList);
        return pageInfo;
    }

//    public List<BookNote> listBookNote(int page, int size,String bookName,String author) {
//        return bookNoteMapper.selectByPage(page, size,bookName,author);
//    }

    public BookNote getBookNoteByBookId(int book_id) {
        return bookNoteMapper.selectByBookId(book_id);
    }

    public BookNote getBookNote(int id) {
        return bookNoteMapper.selectByPrimaryKey(id);
    }

    public List<BookNote> listBookNoteTop(Integer num) {
        return bookNoteMapper.selectTop(num);
    }

    public boolean insertBookNote(){
//        bookNoteMapper.insert(null);
        return false;
    }

    public int deleteNote(int id){
        return bookNoteMapper.deleteByPrimaryKey(id);
    }

    public List<BookNote> queryNote(String name,String author){
        return bookNoteMapper.queryNote(name,author);
    }

    public int insertBookNote(BookNote bookNote) {
        return bookNoteMapper.insert(bookNote);
    }

    public int updateBookNote(BookNote bookNote) {
        return bookNoteMapper.updateByPrimaryKey(bookNote);
    }

    public BookNoteDetail getNoteDetail(Integer id) {
        return bookNoteMapper.getNoteDetail(id);
    }
}
